package com.lxm;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.lxm.entity.wx.WxAcceptEntity;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

/**
 * @author ：Administrator
 * @date :创建时间 2021/12/23 18:36
 */
public class demoNoSpringBoot {
    @Test
    @Disabled
    void ListjoinString(){
        List<String> list = new ArrayList<>();
        list.add("bb");
        list.add("aa");
        list.add("za");
        System.out.println(list);
        Collections.sort(list);
        System.out.println(list);
        String join = String.join("", list);
        System.out.println(join);
    }
    @Test
    @Disabled
    void xmlToBean() throws JsonProcessingException {
        String  xml="<xml><ToUserName><![CDATA[gh_274d524f1132]]></ToUserName>\n" +
                "<FromUserName><![CDATA[o8wA46y1JDNiadkx0h54joqOQboY]]></FromUserName>\n" +
                "<CreateTime>1640258065</CreateTime>\n" +
                "<MsgType><![CDATA[event]]></MsgType>\n" +
                "<Event><![CDATA[subscribe]]></Event>\n" +
                "<EventKey><![CDATA[]]></EventKey>\n" +
                "</xml>";
        ObjectMapper xmlMapper = new XmlMapper();
        // 时间格式化
        xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        xmlMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
        ////字段为null，自动忽略，不再序列化
        xmlMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        ////XML标签名:使用骆驼命名的属性名，
        xmlMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
        xmlMapper.enable(MapperFeature.USE_STD_BEAN_NAMING);
        // //设置转换模式
        WxAcceptEntity wxAcceptEntity = xmlMapper.readValue(xml, WxAcceptEntity.class);
        System.out.println(JSONObject.toJSONString(wxAcceptEntity));

    }

    @Test
    @Disabled
    public void getAuthCode(){
        System.out.println(UUID.randomUUID().toString().replace("-",""));
    }
    @Test
    @Disabled
    public void beanToXml() throws JsonProcessingException {
        WxAcceptEntity wxAcceptEntity = new WxAcceptEntity();
        wxAcceptEntity.setToUserName("123");
        wxAcceptEntity.setFromUserName("321");
        wxAcceptEntity.setCreateTime("654");
        wxAcceptEntity.setMsgType("text");
        wxAcceptEntity.setContent("aaa");
        ObjectMapper xmlMapper = new XmlMapper();
        // 时间格式化
        xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        xmlMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
        ////字段为null，自动忽略，不再序列化
        xmlMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        ////XML标签名:使用骆驼命名的属性名，
        xmlMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
        xmlMapper.enable(MapperFeature.USE_STD_BEAN_NAMING);
        // //设置转换模式
        String s = xmlMapper.writeValueAsString(wxAcceptEntity);
        System.out.println(s);
    }
@Test
    public void stringFormatDemo(){
        String url = "http://127.0.0.1#/showSenMsg?id=%s&authCode=%s";
        String aaaaaaaaaaa = String.format(url, 150, "aaaaaaaaaaa");
        System.out.println(aaaaaaaaaaa);
    }
}
